home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MOR55SRC.ZIP / MORIA / SOURCE / DUNGEON.C < prev    next >
C/C++ Source or Header  |  1992-12-07  |  50KB  |  2,172 lines

  1. /* source/dungeon.c: the main command interpreter, updating player status
  2.  
  3.    Copyright (c) 1989-92 James E. Wilson, Robert A. Koeneke
  4.  
  5.    This software may be copied and distributed for educational, research, and
  6.    not for profit purposes provided that this copyright and statement are
  7.    included in all such copies. */
  8.  
  9. #ifdef __TURBOC__
  10. #include    <conio.h>
  11. #include    <stdio.h>
  12. #include    <stdlib.h>
  13. #endif /* __TURBOC__ */
  14.  
  15. #include "config.h"
  16. #include "constant.h"
  17. #include "types.h"
  18. #include "externs.h"
  19.  
  20. #ifdef USG
  21. #ifndef ATARIST_MWC
  22. #include <string.h>
  23. #endif
  24. #else
  25. #include <strings.h>
  26. #endif
  27.  
  28. #if defined(LINT_ARGS)
  29. static char original_commands(char);
  30. static void do_command(char);
  31. static int valid_countcommand(char);
  32. static void regenhp(int);
  33. static void regenmana(int);
  34. static int enchanted(inven_type *);
  35. static void examine_book(void);
  36. static void go_up(void);
  37. static void go_down(void);
  38. static void jamdoor(void);
  39. static void refill_lamp(void);
  40. #else
  41. static char original_commands();
  42. static void do_command();
  43. static int valid_countcommand();
  44. static void regenhp();
  45. static void regenmana();
  46. static int enchanted();
  47. static void examine_book();
  48. static void go_up();
  49. static void go_down();
  50. static void jamdoor();
  51. static void refill_lamp();
  52. #endif
  53.  
  54. #ifdef ATARIST_TC
  55. /* Include this to get prototypes for standard library functions.  */
  56. #include <stdlib.h>
  57. #endif
  58.  
  59. /* Moria game module                    -RAK-    */
  60. /* The code in this section has gone through many revisions, and */
  61. /* some of it could stand some more hard work.    -RAK-           */
  62.  
  63. /* It has had a bit more hard work.            -CJS- */
  64.  
  65. void dungeon()
  66. {
  67.   int find_count, i;
  68.   int regen_amount;        /* Regenerate hp and mana*/
  69.   char command;        /* Last command         */
  70.   register struct misc *p_ptr;
  71.   register inven_type *i_ptr;
  72.   register struct flags *f_ptr;
  73. #ifdef ATARIST_WMC
  74.   int32u holder;
  75. #endif
  76.  
  77.   /* Main procedure for dungeon.            -RAK-    */
  78.   /* Note: There is a lot of preliminary magic going on here at first*/
  79.  
  80.   /* init pointers. */
  81.   f_ptr = &py.flags;
  82.   p_ptr = &py.misc;
  83.  
  84.   /* Check light status for setup       */
  85.   i_ptr = &inventory[INVEN_LIGHT];
  86.   if (i_ptr->p1 > 0)
  87.     player_light = TRUE;
  88.   else
  89.     player_light = FALSE;
  90.   /* Check for a maximum level           */
  91.   if (dun_level > p_ptr->max_dlv)
  92.     p_ptr->max_dlv = dun_level;
  93.  
  94.   /* Reset flags and initialize variables  */
  95.   command_count = 0;
  96.   find_count = 0;
  97.   new_level_flag    = FALSE;
  98.   find_flag    = FALSE;
  99.   teleport_flag = FALSE;
  100.   mon_tot_mult    = 0;
  101.   cave[char_row][char_col].cptr = 1;
  102.   /* Ensure we display the panel. Used to do this with a global var. -CJS- */
  103.   panel_row = panel_col = -1;
  104.   /* Light up the area around character       */
  105.   check_view ();
  106.   /* must do this after panel_row/col set to -1, because search_off() will
  107.      call check_view(), and so the panel_* variables must be valid before
  108.      search_off() is called */
  109.   if (py.flags.status & PY_SEARCH)
  110.     search_off();
  111.   /* Light,  but do not move critters        */
  112.   creatures(FALSE);
  113.   /* Print the depth               */
  114.   prt_depth();
  115. #if 0
  116.   /* This can't be right.  */
  117. #ifdef ATARIST_MWC
  118.   prt_map();
  119. #endif
  120. #endif
  121.  
  122.   /* Loop until dead,  or new level        */
  123.   do
  124.     {
  125.       /* Increment turn counter            */
  126.       turn++;
  127. #ifndef MAC
  128.       /* The Mac ignores the game hours file        */
  129.       /* Check for game hours                   */
  130.       if (((turn % 250) == 1) && !check_time())
  131.     if (closing_flag > 4)
  132.       {
  133.         msg_print("The gates to Moria are now closed.");
  134.         (void) strcpy (died_from, "(closing gate: saved)");
  135.         if (!save_char())
  136.           {
  137.         (void) strcpy (died_from, "a slammed gate");
  138.         death = TRUE;
  139.           }
  140.         exit_game();
  141.       }
  142.     else
  143.       {
  144.         disturb (0, 0);
  145.         closing_flag++;
  146.         msg_print("The gates to Moria are closing.");
  147.         msg_print("Please finish up or save your game.");
  148.       }
  149. #endif
  150.  
  151.       /* turn over the store contents every, say, 1000 turns */
  152.       if ((dun_level != 0) && ((turn % 1000) == 0))
  153.     store_maint();
  154.  
  155.       /* Check for creature generation        */
  156.       if (randint(MAX_MALLOC_CHANCE) == 1)
  157.     alloc_monster(1, MAX_SIGHT, FALSE);
  158.       /* Check light status                   */
  159.       i_ptr = &inventory[INVEN_LIGHT];
  160.       if (player_light)
  161.     if (i_ptr->p1 > 0)
  162.       {
  163.         i_ptr->p1--;
  164.         if (i_ptr->p1 == 0)
  165.           {
  166.         player_light = FALSE;
  167.         msg_print("Your light has gone out!");
  168.         disturb (0, 1);
  169.         /* unlight creatures */
  170.         creatures(FALSE);
  171.           }
  172.         else if ((i_ptr->p1 < 40) && (randint(5) == 1) &&
  173.              (py.flags.blind < 1))
  174.           {
  175.         disturb (0, 0);
  176.         msg_print("Your light is growing faint.");
  177.           }
  178.       }
  179.     else
  180.       {
  181.         player_light = FALSE;
  182.         disturb (0, 1);
  183.         /* unlight creatures */
  184.         creatures(FALSE);
  185.       }
  186.       else if (i_ptr->p1 > 0)
  187.     {
  188.       i_ptr->p1--;
  189.       player_light = TRUE;
  190.       disturb (0, 1);
  191.       /* light creatures */
  192.       creatures(FALSE);
  193.     }
  194.  
  195.       /* Update counters and messages            */
  196.       /* Check food status           */
  197.       regen_amount = PLAYER_REGEN_NORMAL;
  198.       if (f_ptr->food < PLAYER_FOOD_ALERT)
  199.     {
  200.       if (f_ptr->food < PLAYER_FOOD_WEAK)
  201.         {
  202.           if (f_ptr->food < 0)
  203.         regen_amount = 0;
  204.           else if (f_ptr->food < PLAYER_FOOD_FAINT)
  205.         regen_amount = PLAYER_REGEN_FAINT;
  206.           else if (f_ptr->food < PLAYER_FOOD_WEAK)
  207.         regen_amount = PLAYER_REGEN_WEAK;
  208.           if ((PY_WEAK & f_ptr->status) == 0)
  209.         {
  210.           f_ptr->status |= PY_WEAK;
  211.           msg_print("You are getting weak from hunger.");
  212.           disturb (0, 0);
  213.           prt_hunger();
  214.         }
  215.           if ((f_ptr->food < PLAYER_FOOD_FAINT) && (randint(8) == 1))
  216.         {
  217.           f_ptr->paralysis += randint(5);
  218.           msg_print("You faint from the lack of food.");
  219.           disturb (1, 0);
  220.         }
  221.         }
  222.       else if ((PY_HUNGRY & f_ptr->status) == 0)
  223.         {
  224.           f_ptr->status |= PY_HUNGRY;
  225.           msg_print("You are getting hungry.");
  226.           disturb (0, 0);
  227.           prt_hunger();
  228.         }
  229.     }
  230.       /* Food consumption    */
  231.       /* Note: Speeded up characters really burn up the food!  */
  232.       if (f_ptr->speed < 0)
  233.     f_ptr->food -=    f_ptr->speed*f_ptr->speed;
  234.       f_ptr->food -= f_ptr->food_digested;
  235.       if (f_ptr->food < 0)
  236.     {
  237.       take_hit (-f_ptr->food/16, "starvation");   /* -CJS- */
  238.       disturb(1, 0);
  239.     }
  240.       /* Regenerate           */
  241.       if (f_ptr->regenerate)  regen_amount = regen_amount * 3 / 2;
  242.       if ((py.flags.status & PY_SEARCH) || f_ptr->rest != 0)
  243.     regen_amount = regen_amount * 2;
  244.       if ((py.flags.poisoned < 1) && (p_ptr->chp < p_ptr->mhp))
  245.     regenhp(regen_amount);
  246.       if (p_ptr->cmana < p_ptr->mana)
  247.     regenmana(regen_amount);
  248.       /* Blindness           */
  249.       if (f_ptr->blind > 0)
  250.     {
  251.       if ((PY_BLIND & f_ptr->status) == 0)
  252.         {
  253.           f_ptr->status |= PY_BLIND;
  254.           prt_map();
  255.           prt_blind();
  256.           disturb (0, 1);
  257.           /* unlight creatures */
  258.           creatures (FALSE);
  259.         }
  260.       f_ptr->blind--;
  261.       if (f_ptr->blind == 0)
  262.         {
  263. #ifdef ATARIST_MWC
  264.           f_ptr->status &= ~(holder = PY_BLIND);
  265. #else
  266.           f_ptr->status &= ~PY_BLIND;
  267. #endif
  268.           prt_blind();
  269.           prt_map();
  270.           /* light creatures */
  271.           disturb (0, 1);
  272.           creatures(FALSE);
  273.           msg_print("The veil of darkness lifts.");
  274.         }
  275.     }
  276.       /* Confusion           */
  277.       if (f_ptr->confused > 0)
  278.     {
  279.       if ((PY_CONFUSED & f_ptr->status) == 0)
  280.         {
  281.           f_ptr->status |= PY_CONFUSED;
  282.           prt_confused();
  283.         }
  284.       f_ptr->confused--;
  285.       if (f_ptr->confused == 0)
  286.         {
  287. #ifdef ATARIST_MWC
  288.           f_ptr->status &= ~(holder = PY_CONFUSED);
  289. #else
  290.           f_ptr->status &= ~PY_CONFUSED;
  291. #endif
  292.           prt_confused();
  293.           msg_print("You feel less confused now.");
  294.           if (py.flags.rest != 0)
  295.         rest_off ();
  296.         }
  297.     }
  298.       /* Afraid               */
  299.       if (f_ptr->afraid > 0)
  300.     {
  301.       if ((PY_FEAR & f_ptr->status) == 0)
  302.         {
  303.           if ((f_ptr->shero+f_ptr->hero) > 0)
  304.         f_ptr->afraid = 0;
  305.           else
  306.         {
  307.           f_ptr->status |= PY_FEAR;
  308.           prt_afraid();
  309.         }
  310.         }
  311.       else if ((f_ptr->shero+f_ptr->hero) > 0)
  312.         f_ptr->afraid = 1;
  313.       f_ptr->afraid--;
  314.       if (f_ptr->afraid == 0)
  315.         {
  316. #ifdef ATARIST_MWC
  317.           f_ptr->status &= ~(holder = PY_FEAR);
  318. #else
  319.           f_ptr->status &= ~PY_FEAR;
  320. #endif
  321.           prt_afraid();
  322.           msg_print("You feel bolder now.");
  323.           disturb (0, 0);
  324.         }
  325.     }
  326.       /* Poisoned           */
  327.       if (f_ptr->poisoned > 0)
  328.     {
  329.       if ((PY_POISONED & f_ptr->status) == 0)
  330.         {
  331.           f_ptr->status |= PY_POISONED;
  332.           prt_poisoned();
  333.         }
  334.       f_ptr->poisoned--;
  335.       if (f_ptr->poisoned == 0)
  336.         {
  337. #ifdef ATARIST_MWC
  338.           f_ptr->status &= ~(holder = PY_POISONED);
  339. #else
  340.           f_ptr->status &= ~PY_POISONED;
  341. #endif
  342.           prt_poisoned();
  343.           msg_print("You feel better.");
  344.           disturb (0, 0);
  345.         }
  346.       else
  347.         {
  348.           switch(con_adj())
  349.         {
  350.         case -4:  i = 4;  break;
  351.         case -3:
  352.         case -2:  i = 3;  break;
  353.         case -1:  i = 2;  break;
  354.         case 0:      i = 1;  break;
  355.         case 1: case 2: case 3:
  356.           i = ((turn % 2) == 0);
  357.           break;
  358.         case 4: case 5:
  359.           i = ((turn % 3) == 0);
  360.           break;
  361.         case 6:
  362.           i = ((turn % 4) == 0);
  363.           break;
  364.         }
  365.           take_hit (i, "poison");
  366.           disturb (1, 0);
  367.         }
  368.     }
  369.       /* Fast               */
  370.       if (f_ptr->fast > 0)
  371.     {
  372.       if ((PY_FAST & f_ptr->status) == 0)
  373.         {
  374.           f_ptr->status |= PY_FAST;
  375.           change_speed(-1);
  376.           msg_print("You feel yourself moving faster.");
  377.           disturb (0, 0);
  378.         }
  379.       f_ptr->fast--;
  380.       if (f_ptr->fast == 0)
  381.         {
  382. #ifdef ATARIST_MWC
  383.           f_ptr->status &= ~(holder = PY_FAST);
  384. #else
  385.           f_ptr->status &= ~PY_FAST;
  386. #endif
  387.           change_speed(1);
  388.           msg_print("You feel yourself slow down.");
  389.           disturb (0, 0);
  390.         }
  391.     }
  392.       /* Slow               */
  393.       if (f_ptr->slow > 0)
  394.     {
  395.       if ((PY_SLOW & f_ptr->status) == 0)
  396.         {
  397.           f_ptr->status |= PY_SLOW;
  398.           change_speed(1);
  399.           msg_print("You feel yourself moving slower.");
  400.           disturb (0, 0);
  401.         }
  402.       f_ptr->slow--;
  403.       if (f_ptr->slow == 0)
  404.         {
  405. #ifdef ATARIST_MWC
  406.           f_ptr->status &= ~(holder = PY_SLOW);
  407. #else
  408.           f_ptr->status &= ~PY_SLOW;
  409. #endif
  410.           change_speed(-1);
  411.           msg_print("You feel yourself speed up.");
  412.           disturb (0, 0);
  413.         }
  414.     }
  415.       /* Resting is over?      */
  416.       if (f_ptr->rest > 0)
  417.     {
  418.       f_ptr->rest--;
  419.       if (f_ptr->rest == 0)              /* Resting over           */
  420.         rest_off();
  421.     }
  422.       else if (f_ptr->rest < 0)
  423.     {
  424.       /* Rest until reach max mana and max hit points.  */
  425.       f_ptr->rest++;
  426.       if ((p_ptr->chp == p_ptr->mhp && p_ptr->cmana == p_ptr->mana)
  427.           || f_ptr->rest == 0)
  428.         rest_off();
  429.     }
  430.  
  431.       /* Check for interrupts to find or rest. */
  432. #ifdef MAC
  433.       /* On Mac, checking for input is expensive, since it involves handling
  434.      events, so we only check in multiples of 16 turns. */
  435.       if (!(turn & 0xF) && ((command_count > 0) || find_flag
  436.                  || (f_ptr->rest != 0)))
  437.     if (macgetkey(CNIL, TRUE))
  438.       disturb(0, 0);
  439. #else
  440.       if ((command_count > 0 || find_flag || f_ptr->rest != 0)
  441. #if defined(MSDOS) || defined(VMS)
  442.       && kbhit()
  443. #else
  444.       && (check_input (find_flag ? 0 : 10000))
  445. #endif
  446.       )
  447.     {
  448. #ifdef MSDOS
  449.       (void) msdos_getch();
  450. #endif
  451. #ifdef VMS
  452.       /* Get and ignore the key used to interrupt resting/running.  */
  453.       (void) vms_getch ();
  454. #endif
  455.       disturb (0, 0);
  456.     }
  457. #endif
  458.  
  459.       /* Hallucinating?     (Random characters appear!)*/
  460.       if (f_ptr->image > 0)
  461.     {
  462.       end_find ();
  463.       f_ptr->image--;
  464.       if (f_ptr->image == 0)
  465.         prt_map ();     /* Used to draw entire screen! -CJS- */
  466.     }
  467.       /* Paralysis           */
  468.       if (f_ptr->paralysis > 0)
  469.     {
  470.       /* when paralysis true, you can not see any movement that occurs */
  471.       f_ptr->paralysis--;
  472.       disturb (1, 0);
  473.     }
  474.       /* Protection from evil counter*/
  475.       if (f_ptr->protevil > 0)
  476.     {
  477.       f_ptr->protevil--;
  478.       if (f_ptr->protevil == 0)
  479.         msg_print ("You no longer feel safe from evil.");
  480.     }
  481.       /* Invulnerability    */
  482.       if (f_ptr->invuln > 0)
  483.     {
  484.       if ((PY_INVULN & f_ptr->status) == 0)
  485.         {
  486.           f_ptr->status |= PY_INVULN;
  487.           disturb (0, 0);
  488.           py.misc.pac += 100;
  489.           py.misc.dis_ac += 100;
  490.           prt_pac();
  491.           msg_print("Your skin turns into steel!");
  492.         }
  493.       f_ptr->invuln--;
  494.       if (f_ptr->invuln == 0)
  495.         {
  496. #ifdef ATARIST_MWC
  497.           f_ptr->status &= ~(holder = PY_INVULN);
  498. #else
  499.           f_ptr->status &= ~PY_INVULN;
  500. #endif
  501.           disturb (0, 0);
  502.           py.misc.pac -= 100;
  503.           py.misc.dis_ac -= 100;
  504.           prt_pac();
  505.           msg_print("Your skin returns to normal.");
  506.         }
  507.     }
  508.       /* Heroism       */
  509.       if (f_ptr->hero > 0)
  510.     {
  511.       if ((PY_HERO & f_ptr->status) == 0)
  512.         {
  513.           f_ptr->status |= PY_HERO;
  514.           disturb (0, 0);
  515.           p_ptr->mhp += 10;
  516.           p_ptr->chp += 10;
  517.           p_ptr->bth += 12;
  518.           p_ptr->bthb+= 12;
  519.           msg_print("You feel like a HERO!");
  520.           prt_mhp();
  521.           prt_chp();
  522.         }
  523.       f_ptr->hero--;
  524.       if (f_ptr->hero == 0)
  525.         {
  526. #ifdef ATARIST_MWC
  527.           f_ptr->status &= ~(holder = PY_HERO);
  528. #else
  529.           f_ptr->status &= ~PY_HERO;
  530. #endif
  531.           disturb (0, 0);
  532.           p_ptr->mhp -= 10;
  533.           if (p_ptr->chp > p_ptr->mhp)
  534.         {
  535.           p_ptr->chp = p_ptr->mhp;
  536.           p_ptr->chp_frac = 0;
  537.           prt_chp();
  538.         }
  539.           p_ptr->bth -= 12;
  540.           p_ptr->bthb-= 12;
  541.           msg_print("The heroism wears off.");
  542.           prt_mhp();
  543.         }
  544.     }
  545.       /* Super Heroism */
  546.       if (f_ptr->shero > 0)
  547.     {
  548.       if ((PY_SHERO & f_ptr->status) == 0)
  549.         {
  550.           f_ptr->status |= PY_SHERO;
  551.           disturb (0, 0);
  552.           p_ptr->mhp += 20;
  553.           p_ptr->chp += 20;
  554.           p_ptr->bth += 24;
  555.           p_ptr->bthb+= 24;
  556.           msg_print("You feel like a SUPER HERO!");
  557.           prt_mhp();
  558.           prt_chp();
  559.         }
  560.       f_ptr->shero--;
  561.       if (f_ptr->shero == 0)
  562.         {
  563. #ifdef ATARIST_MWC
  564.           f_ptr->status &= ~(holder = PY_SHERO);
  565. #else
  566.           f_ptr->status &= ~PY_SHERO;
  567. #endif
  568.           disturb (0, 0);
  569.           p_ptr->mhp -= 20;
  570.           if (p_ptr->chp > p_ptr->mhp)
  571.         {
  572.           p_ptr->chp = p_ptr->mhp;
  573.           p_ptr->chp_frac = 0;
  574.           prt_chp();
  575.         }
  576.           p_ptr->bth -= 24;
  577.           p_ptr->bthb-= 24;
  578.           msg_print("The super heroism wears off.");
  579.           prt_mhp();
  580.         }
  581.     }
  582.       /* Blessed       */
  583.       if (f_ptr->blessed > 0)
  584.     {
  585.       if ((PY_BLESSED & f_ptr->status) == 0)
  586.         {
  587.           f_ptr->status |= PY_BLESSED;
  588.           disturb (0, 0);
  589.           p_ptr->bth += 5;
  590.           p_ptr->bthb+= 5;
  591.           p_ptr->pac += 2;
  592.           p_ptr->dis_ac+= 2;
  593.           msg_print("You feel righteous!");
  594.           prt_pac();
  595.         }
  596.       f_ptr->blessed--;
  597.       if (f_ptr->blessed == 0)
  598.         {
  599. #ifdef ATARIST_MWC
  600.           f_ptr->status &= ~(holder = PY_BLESSED);
  601. #else
  602.           f_ptr->status &= ~PY_BLESSED;
  603. #endif
  604.           disturb (0, 0);
  605.           p_ptr->bth -= 5;
  606.           p_ptr->bthb-= 5;
  607.           p_ptr->pac -= 2;
  608.           p_ptr->dis_ac -= 2;
  609.           msg_print("The prayer has expired.");
  610.           prt_pac();
  611.         }
  612.     }
  613.       /* Resist Heat   */
  614.       if (f_ptr->resist_heat > 0)
  615.     {
  616.       f_ptr->resist_heat--;
  617.       if (f_ptr->resist_heat == 0)
  618.         msg_print ("You no longer feel safe from flame.");
  619.     }
  620.       /* Resist Cold   */
  621.       if (f_ptr->resist_cold > 0)
  622.     {
  623.       f_ptr->resist_cold--;
  624.       if (f_ptr->resist_cold == 0)
  625.         msg_print ("You no longer feel safe from cold.");
  626.     }
  627.       /* Detect Invisible      */
  628.       if (f_ptr->detect_inv > 0)
  629.     {
  630. #ifdef ATARIST_MWC
  631.       if (((holder = PY_DET_INV) & f_ptr->status) == 0)
  632. #else
  633.       if ((PY_DET_INV & f_ptr->status) == 0)
  634. #endif
  635.         {
  636. #ifdef ATARIST_MWC
  637.           f_ptr->status |= holder;
  638. #else
  639.           f_ptr->status |= PY_DET_INV;
  640. #endif
  641.           f_ptr->see_inv = TRUE;
  642.           /* light but don't move creatures */
  643.           creatures (FALSE);
  644.         }
  645.       f_ptr->detect_inv--;
  646.       if (f_ptr->detect_inv == 0)
  647.         {
  648. #ifdef ATARIST_MWC
  649.           f_ptr->status &= ~holder;
  650. #else
  651.           f_ptr->status &= ~PY_DET_INV;
  652. #endif
  653.           /* may still be able to see_inv if wearing magic item */
  654.           calc_bonuses();
  655.           /* unlight but don't move creatures */
  656.           creatures (FALSE);
  657.         }
  658.     }
  659.       /* Timed infra-vision    */
  660.       if (f_ptr->tim_infra > 0)
  661.     {
  662. #ifdef ATARIST_MWC
  663.       if (((holder = PY_TIM_INFRA) & f_ptr->status) == 0)
  664. #else
  665.       if ((PY_TIM_INFRA & f_ptr->status) == 0)
  666. #endif
  667.         {
  668. #ifdef ATARIST_MWC
  669.           f_ptr->status |= holder;
  670. #else
  671.           f_ptr->status |= PY_TIM_INFRA;
  672. #endif
  673.           f_ptr->see_infra++;
  674.           /* light but don't move creatures */
  675.           creatures (FALSE);
  676.         }
  677.       f_ptr->tim_infra--;
  678.       if (f_ptr->tim_infra == 0)
  679.         {
  680. #ifdef ATARIST_MWC
  681.           f_ptr->status &= ~holder;
  682. #else
  683.           f_ptr->status &= ~PY_TIM_INFRA;
  684. #endif
  685.           f_ptr->see_infra--;
  686.           /* unlight but don't move creatures */
  687.           creatures (FALSE);
  688.         }
  689.     }
  690.     /* Word-of-Recall  Note: Word-of-Recall is a delayed action     */
  691.       if (f_ptr->word_recall > 0)
  692.     if (f_ptr->word_recall == 1)
  693.       {
  694.         new_level_flag = TRUE;
  695.         f_ptr->paralysis++;
  696.         f_ptr->word_recall = 0;
  697.         if (dun_level > 0)
  698.           {
  699.         dun_level = 0;
  700.         msg_print("You feel yourself yanked upwards!");
  701.           }
  702.         else if (py.misc.max_dlv != 0)
  703.           {
  704.         dun_level = py.misc.max_dlv;
  705.         msg_print("You feel yourself yanked downwards!");
  706.           }
  707.       }
  708.     else
  709.       f_ptr->word_recall--;
  710.  
  711.       /* Random teleportation  */
  712.       if ((py.flags.teleport) && (randint(100) == 1))
  713.     {
  714.       disturb (0, 0);
  715.       teleport(40);
  716.     }
  717.  
  718.       /* See if we are too weak to handle the weapon or pack.  -CJS- */
  719. #ifdef ATARIST_MWC
  720.       if (py.flags.status & (holder = PY_STR_WGT))
  721. #else
  722.       if (py.flags.status & PY_STR_WGT)
  723. #endif
  724.     check_strength();
  725.       if (py.flags.status & PY_STUDY)
  726.     prt_study();
  727. #ifdef ATARIST_MWC
  728.       if (py.flags.status & (holder = PY_SPEED))
  729. #else
  730.       if (py.flags.status & PY_SPEED)
  731. #endif
  732.     {
  733. #ifdef ATARIST_MWC
  734.       py.flags.status &= ~holder;
  735. #else
  736.       py.flags.status &= ~PY_SPEED;
  737. #endif
  738.       prt_speed();
  739.     }
  740. #ifdef ATARIST_MWC
  741.       if ((py.flags.status & (holder = PY_PARALYSED))
  742.       && (py.flags.paralysis < 1))
  743. #else
  744.       if ((py.flags.status & PY_PARALYSED) && (py.flags.paralysis < 1))
  745. #endif
  746.     {
  747.       prt_state();
  748. #ifdef ATARIST_MWC
  749.       py.flags.status &= ~holder;
  750. #else
  751.       py.flags.status &= ~PY_PARALYSED;
  752. #endif
  753.     }
  754.       else if (py.flags.paralysis > 0)
  755.     {
  756.       prt_state();
  757. #ifdef ATARIST_MWC
  758.       py.flags.status |= (holder = PY_PARALYSED);
  759. #else
  760.       py.flags.status |= PY_PARALYSED;
  761. #endif
  762.     }
  763.       else if (py.flags.rest != 0)
  764.     prt_state();
  765.  
  766. #ifdef ATARIST_MWC
  767.       if ((py.flags.status & (holder = PY_ARMOR)) != 0)
  768. #else
  769.       if ((py.flags.status & PY_ARMOR) != 0)
  770. #endif
  771.     {
  772.       prt_pac();
  773. #ifdef ATARIST_MWC
  774.       py.flags.status &= ~holder;
  775. #else
  776.       py.flags.status &= ~PY_ARMOR;
  777. #endif
  778.     }
  779. #ifdef ATARIST_MWC
  780.       if ((py.flags.status & (holder = PY_STATS)) != 0)
  781. #else
  782.       if ((py.flags.status & PY_STATS) != 0)
  783. #endif
  784.     {
  785.       for (i = 0; i < 6; i++)
  786. #ifdef ATARIST_MWC
  787.         if (((holder = PY_STR) << i) & py.flags.status)
  788. #else
  789.         if ((PY_STR << i) & py.flags.status)
  790. #endif
  791.           prt_stat(i);
  792. #ifdef ATARIST_MWC
  793.       py.flags.status &= ~(holder = PY_STATS);
  794. #else
  795.       py.flags.status &= ~PY_STATS;
  796. #endif
  797.     }
  798. #ifdef ATARIST_MWC
  799.       if (py.flags.status & (holder = PY_HP))
  800. #else
  801.       if (py.flags.status & PY_HP)
  802. #endif
  803.     {
  804.       prt_mhp();
  805.       prt_chp();
  806. #ifdef ATARIST_MWC
  807.       py.flags.status &= ~holder;
  808. #else
  809.       py.flags.status &= ~PY_HP;
  810. #endif
  811.     }
  812. #ifdef ATARIST_MWC
  813.       if (py.flags.status & (holder = PY_MANA))
  814. #else
  815.       if (py.flags.status & PY_MANA)
  816. #endif
  817.     {
  818.       prt_cmana();
  819. #ifdef ATARIST_MWC
  820.       py.flags.status &= ~holder;
  821. #else
  822.       py.flags.status &= ~PY_MANA;
  823. #endif
  824.     }
  825.  
  826.       /* Allow for a slim chance of detect enchantment -CJS- */
  827.       /* for 1st level char, check once every 2160 turns
  828.      for 40th level char, check once every 416 turns */
  829.       if (((turn & 0xF) == 0) && (f_ptr->confused == 0)
  830.       && (randint((int)(10 + 750 / (5 + py.misc.lev))) == 1))
  831.     {
  832.       vtype tmp_str;
  833.  
  834.       for (i = 0; i < INVEN_ARRAY_SIZE; i++)
  835.         {
  836.           if (i == inven_ctr)
  837.         i = 22;
  838.           i_ptr = &inventory[i];
  839.           /* if in inventory, succeed 1 out of 50 times,
  840.          if in equipment list, success 1 out of 10 times */
  841.           if ((i_ptr->tval != TV_NOTHING) && enchanted(i_ptr) &&
  842.           (randint(i < 22 ? 50 : 10) == 1))
  843.         {
  844.           extern char *describe_use();
  845.  
  846.           (void) sprintf(tmp_str,
  847.                  "There's something about what you are %s...",
  848.                  describe_use(i));
  849.           disturb(0, 0);
  850.           msg_print(tmp_str);
  851.           add_inscribe(i_ptr, ID_MAGIK);
  852.         }
  853.         }
  854.     }
  855.  
  856.       /* Check the state of the monster list, and delete some monsters if
  857.      the monster list is nearly full.  This helps to avoid problems in
  858.      creature.c when monsters try to multiply.  Compact_monsters() is
  859.      much more likely to succeed if called from here, than if called
  860.      from within creatures().  */
  861.       if (MAX_MALLOC - mfptr < 10)
  862.     (void) compact_monsters ();
  863.  
  864.       if ((py.flags.paralysis < 1) &&         /* Accept a command?     */
  865.       (py.flags.rest == 0) &&
  866.       (!death))
  867.     /* Accept a command and execute it                 */
  868.     {
  869.       do
  870.         {
  871. #ifdef ATARIST_MWC
  872.           if (py.flags.status & (holder = PY_REPEAT))
  873. #else
  874.           if (py.flags.status & PY_REPEAT)
  875. #endif
  876.         prt_state ();
  877.           default_dir = FALSE;
  878.           free_turn_flag = FALSE;
  879.  
  880.           if (find_flag)
  881.         {
  882.           find_run();
  883.           find_count--;
  884.           if (find_count == 0)
  885.             end_find();
  886.           put_qio();
  887.         }
  888.           else if (doing_inven)
  889.         inven_command (doing_inven);
  890.           else
  891.         {
  892.           /* move the cursor to the players character */
  893.           move_cursor_relative (char_row, char_col);
  894.           if (command_count > 0)
  895.             {
  896.               msg_flag = FALSE;
  897.               default_dir = TRUE;
  898.             }
  899.           else
  900.             {
  901.               msg_flag = FALSE;
  902. #ifdef MAC
  903.               unloadsegments();
  904.               enablesavecmd(TRUE);
  905.               command = inkeydir();
  906.               enablesavecmd(FALSE);
  907. #else
  908.               command = inkey();
  909. #endif
  910.               i = 0;
  911.               /* Get a count for a command. */
  912.               if ((rogue_like_commands
  913.                && command >= '0' && command <= '9')
  914.               || (!rogue_like_commands && command == '#'))
  915.             {
  916.               char tmp[8];
  917.  
  918.               prt("Repeat count:", 0, 0);
  919.               if (command == '#')
  920.                 command = '0';
  921.               i = 0;
  922.               while (TRUE)
  923.                 {
  924.                   if (command == DELETE || command == CTRL('H'))
  925.                 {
  926.                   i = i / 10;
  927.                   (void) sprintf(tmp, "%d", i);
  928.                   prt (tmp, 0, 14);
  929.                 }
  930.                   else if (command >= '0' && command <= '9')
  931.                 {
  932.                       if (i > 99)
  933.                     bell ();
  934.                   else
  935.                     {
  936.                       i = i * 10 + command - '0';
  937.                       (void) sprintf (tmp, "%d", i);
  938.                       prt (tmp, 0, 14);
  939.                     }
  940.                 }
  941.                   else
  942.                 break;
  943. #ifdef MAC
  944.                   command = inkeydir();
  945. #else
  946.                   command = inkey();
  947. #endif
  948.                 }
  949.               if (i == 0)
  950.                 {
  951.                   i = 99;
  952.                   (void) sprintf (tmp, "%d", i);
  953.                   prt (tmp, 0, 14);
  954.                 }
  955.               /* a special hack to allow numbers as commands */
  956.               if (command == ' ')
  957.                 {
  958.                   prt ("Command:", 0, 20);
  959. #ifdef MAC
  960.                   command = inkeydir();
  961. #else
  962.                   command = inkey();
  963. #endif
  964.                 }
  965.             }
  966.               /* Another way of typing control codes -CJS- */
  967.               if (command == '^')
  968.             {
  969.               if (command_count > 0)
  970.                 prt_state();
  971.               if (get_com("Control-", &command))
  972.                 {
  973.                   if (command >= 'A' && command <= 'Z')
  974.                 command -= 'A' - 1;
  975.                   else if (command >= 'a' && command <= 'z')
  976.                 command -= 'a' - 1;
  977.                   else
  978.                 {
  979.                    msg_print("Type ^ <letter> for a control char");
  980.                   command = ' ';
  981.                 }
  982.                 }
  983.               else
  984.                 command = ' ';
  985.             }
  986.               /* move cursor to player char again, in case it moved */
  987.               move_cursor_relative (char_row, char_col);
  988.               /* Commands are always converted to rogue form. -CJS- */
  989.               if (rogue_like_commands == FALSE)
  990.             command = original_commands (command);
  991.               if (i > 0)
  992.             {
  993.               if (!valid_countcommand(command))
  994.                 {
  995.                   free_turn_flag = TRUE;
  996.                   msg_print ("Invalid command with a count.");
  997.                   command = ' ';
  998.                 }
  999.               else
  1000.                 {
  1001.                   command_count = i;
  1002.                   prt_state ();
  1003.                 }
  1004.             }
  1005.             }
  1006.           /* Flash the message line. */
  1007.           erase_line(MSG_LINE, 0);
  1008.           move_cursor_relative(char_row, char_col);
  1009.           put_qio();
  1010.  
  1011.           do_command (command);
  1012.           /* Find is counted differently, as the command changes. */
  1013.           if (find_flag)
  1014.             {
  1015.               find_count = command_count - 1;
  1016.               command_count = 0;
  1017.             }
  1018.           else if (free_turn_flag)
  1019.             command_count = 0;
  1020.           else if (command_count)
  1021.             command_count--;
  1022.         }
  1023.           /* End of commands                     */
  1024.         }
  1025.       while (free_turn_flag && !new_level_flag && !eof_flag);
  1026.     }
  1027.       else
  1028.     {
  1029.       /* if paralyzed, resting, or dead, flush output */
  1030.       /* but first move the cursor onto the player, for aesthetics */
  1031.       move_cursor_relative (char_row, char_col);
  1032.       put_qio ();
  1033.     }
  1034.  
  1035.       /* Teleport?               */
  1036.       if (teleport_flag)  teleport(100);
  1037.       /* Move the creatures           */
  1038.       if (!new_level_flag)  creatures(TRUE);
  1039.       /* Exit when new_level_flag is set   */
  1040.     }
  1041.   while (!new_level_flag && !eof_flag);
  1042. }
  1043.  
  1044.  
  1045. static char original_commands(com_val)
  1046. char com_val;
  1047. {
  1048.   int dir_val;
  1049.  
  1050.   switch(com_val)
  1051.     {
  1052.     case CTRL('K'):    /*^K = exit    */
  1053.       com_val = 'Q';
  1054.       break;
  1055.     case CTRL('J'):
  1056.     case CTRL('M'):
  1057.       com_val = '+';
  1058.       break;
  1059.     case CTRL('P'):    /*^P = repeat  */
  1060.     case CTRL('W'):    /*^W = password*/
  1061.     case CTRL('X'):    /*^X = save    */
  1062.     case ' ':
  1063.     case '!':
  1064.     case '$':
  1065.       break;
  1066.     case '.':
  1067.       if (get_dir(CNIL, &dir_val))
  1068.     switch (dir_val)
  1069.       {
  1070.       case 1:    com_val = 'B';    break;
  1071.       case 2:    com_val = 'J';    break;
  1072.       case 3:    com_val = 'N';    break;
  1073.       case 4:    com_val = 'H';    break;
  1074.       case 6:    com_val = 'L';    break;
  1075.       case 7:    com_val = 'Y';    break;
  1076.       case 8:    com_val = 'K';    break;
  1077.       case 9:    com_val = 'U';    break;
  1078.       default:   com_val = ' ';    break;
  1079.       }
  1080.       else
  1081.     com_val = ' ';
  1082.       break;
  1083.     case '/':
  1084.     case '<':
  1085.     case '>':
  1086.     case '-':
  1087.     case '=':
  1088.     case '{':
  1089.     case '?':
  1090.     case 'A':
  1091.       break;
  1092.     case '1':
  1093.       com_val = 'b';
  1094.       break;
  1095.     case '2':
  1096.       com_val = 'j';
  1097.       break;
  1098.     case '3':
  1099.       com_val = 'n';
  1100.       break;
  1101.     case '4':
  1102.       com_val = 'h';
  1103.       break;
  1104.     case '5':    /* Rest one turn */
  1105.       com_val = '.';
  1106.       break;
  1107.     case '6':
  1108.       com_val = 'l';
  1109.       break;
  1110.     case '7':
  1111.       com_val = 'y';
  1112.       break;
  1113.     case '8':
  1114.       com_val = 'k';
  1115.       break;
  1116.     case '9':
  1117.       com_val = 'u';
  1118.       break;
  1119.     case 'B':
  1120.       com_val = 'f';
  1121.       break;
  1122.     case 'C':
  1123.     case 'D':
  1124.     case 'E':
  1125.     case 'F':
  1126.     case 'G':
  1127.       break;
  1128.     case 'L':
  1129.       com_val = 'W';
  1130.       break;
  1131.     case 'M':
  1132.       break;
  1133.     case 'R':
  1134.       break;
  1135.     case 'S':
  1136.       com_val = '#';
  1137.       break;
  1138.     case 'T':
  1139.       if (get_dir(CNIL, &dir_val))
  1140.     switch (dir_val)
  1141.       {
  1142.       case 1:    com_val = CTRL('B');    break;
  1143.       case 2:    com_val = CTRL('J');    break;
  1144.       case 3:    com_val = CTRL('N');    break;
  1145.       case 4:    com_val = CTRL('H');    break;
  1146.       case 6:    com_val = CTRL('L');    break;
  1147.       case 7:    com_val = CTRL('Y');    break;
  1148.       case 8:    com_val = CTRL('K');    break;
  1149.       case 9:    com_val = CTRL('U');    break;
  1150.       default:   com_val = ' ';         break;
  1151.       }
  1152.       else
  1153.     com_val = ' ';
  1154.       break;
  1155.     case 'V':
  1156.       break;
  1157.     case 'a':
  1158.       com_val = 'z';
  1159.       break;
  1160.     case 'b':
  1161.       com_val = 'P';
  1162.       break;
  1163.     case 'c':
  1164.     case 'd':
  1165.     case 'e':
  1166.       break;
  1167.     case 'f':
  1168.       com_val = 't';
  1169.       break;
  1170.     case 'h':
  1171.       com_val = '?';
  1172.       break;
  1173.     case 'i':
  1174.       break;
  1175.     case 'j':
  1176.       com_val = 'S';
  1177.       break;
  1178.     case 'l':
  1179.       com_val = 'x';
  1180.       break;
  1181.     case 'm':
  1182.     case 'o':
  1183.     case 'p':
  1184.     case 'q':
  1185.     case 'r':
  1186.     case 's':
  1187.       break;
  1188.     case 't':
  1189.       com_val = 'T';
  1190.       break;
  1191.     case 'u':
  1192.       com_val = 'Z';
  1193.       break;
  1194.     case 'v':
  1195.     case 'w':
  1196.       break;
  1197.     case 'x':
  1198.       com_val = 'X';
  1199.       break;
  1200.  
  1201.       /* wizard mode commands follow */
  1202.     case CTRL('A'): /*^A = cure all */
  1203.       break;
  1204.     case CTRL('B'):    /*^B = objects */
  1205.       com_val = CTRL('O');
  1206.       break;
  1207.     case CTRL('D'):    /*^D = up/down */
  1208.       break;
  1209.     case CTRL('H'):    /*^H = wizhelp */
  1210.       com_val = '\\';
  1211.       break;
  1212.     case CTRL('I'):    /*^I = identify*/
  1213.       break;
  1214.     case CTRL('L'):    /*^L = wizlight*/
  1215.       com_val = '*';
  1216.       break;
  1217.     case ':':
  1218.     case CTRL('T'):    /*^T = teleport*/
  1219.     case CTRL('E'):    /*^E = wizchar */
  1220.     case CTRL('F'):    /*^F = genocide*/
  1221.     case CTRL('G'):    /*^G = treasure*/
  1222.     case '@':
  1223.     case '+':
  1224.       break;
  1225.     case CTRL('U'):    /*^U = summon  */
  1226.       com_val = '&';
  1227.       break;
  1228.     default:
  1229.       com_val = '~';  /* Anything illegal. */
  1230.       break;
  1231.     }
  1232.   return com_val;
  1233. }
  1234.  
  1235.  
  1236. static void do_command(com_val)
  1237. char com_val;
  1238. {
  1239.   int dir_val, do_pickup;
  1240.   int y, x, i, j;
  1241.   vtype out_val, tmp_str;
  1242.   register struct flags *f_ptr;
  1243.  
  1244.   /* hack for move without pickup.  Map '-' to a movement command. */
  1245.   if (com_val == '-')
  1246.     {
  1247.       do_pickup = FALSE;
  1248.       i = command_count;
  1249.       if (get_dir(CNIL, &dir_val))
  1250.     {
  1251.       command_count = i;
  1252.       switch (dir_val)
  1253.         {
  1254.         case 1:    com_val = 'b';     break;
  1255.         case 2:    com_val = 'j';     break;
  1256.         case 3:    com_val = 'n';     break;
  1257.         case 4:    com_val = 'h';     break;
  1258.         case 6:    com_val = 'l';     break;
  1259.         case 7:    com_val = 'y';     break;
  1260.         case 8:    com_val = 'k';     break;
  1261.         case 9:    com_val = 'u';     break;
  1262.         default:   com_val = '~';     break;
  1263.         }
  1264.     }
  1265.       else
  1266.     com_val = ' ';
  1267.     }
  1268.   else
  1269.     do_pickup = TRUE;
  1270.  
  1271.   switch(com_val)
  1272.     {
  1273.     case 'Q':    /* (Q)uit        (^K)ill */
  1274.       flush();
  1275.       if (get_check("Do you really want to quit?"))
  1276.     {
  1277.       new_level_flag = TRUE;
  1278.       death = TRUE;
  1279.       (void) strcpy(died_from, "Quitting");
  1280.     }
  1281.       free_turn_flag = TRUE;
  1282.       break;
  1283.     case CTRL('P'):    /* (^P)revious message. */
  1284.       if (command_count > 0)
  1285.     {
  1286.       i = command_count;
  1287.       if (i > MAX_SAVE_MSG)
  1288.         i = MAX_SAVE_MSG;
  1289.       command_count = 0;
  1290.     }
  1291.       else if (last_command != CTRL('P'))
  1292.     i = 1;
  1293.       else
  1294.     i = MAX_SAVE_MSG;
  1295.       j = last_msg;
  1296.       if (i > 1)
  1297.     {
  1298.       save_screen();
  1299.       x = i;
  1300.       while (i > 0)
  1301.         {
  1302.           i--;
  1303.           prt(old_msg[j], i, 0);
  1304.           if (j == 0)
  1305.         j = MAX_SAVE_MSG-1;
  1306.           else
  1307.         j--;
  1308.         }
  1309.       erase_line (x, 0);
  1310.       pause_line(x);
  1311.       restore_screen();
  1312.     }
  1313.       else
  1314.     {
  1315.       /* Distinguish real and recovered messages with a '>'. -CJS- */
  1316.       put_buffer(">", 0, 0);
  1317.       prt(old_msg[j], 0, 1);
  1318.     }
  1319.       free_turn_flag = TRUE;
  1320.       break;
  1321.     case CTRL('W'):    /* (^W)izard mode */
  1322.       if (wizard)
  1323.     {
  1324.       wizard = FALSE;
  1325.       msg_print("Wizard mode off.");
  1326.     }
  1327.       else if (enter_wiz_mode())
  1328.     msg_print("Wizard mode on.");
  1329.       prt_winner();
  1330.       free_turn_flag = TRUE;
  1331.       break;
  1332.     case CTRL('X'):    /* e(^X)it and save */
  1333.       if (total_winner)
  1334.     {
  1335.        msg_print("You are a Total Winner,  your character must be retired.");
  1336.       if (rogue_like_commands)
  1337.         msg_print("Use 'Q' to when you are ready to quit.");
  1338.       else
  1339.         msg_print ("Use <Control>-K when you are ready to quit.");
  1340.     }
  1341.       else
  1342.     {
  1343.       (void) strcpy (died_from, "(saved)");
  1344.       msg_print ("Saving game...");
  1345. #ifdef MAC
  1346.       if (save_char (TRUE))
  1347.         exit_game();
  1348. #else
  1349.       if (save_char ())
  1350.         exit_game();
  1351. #endif
  1352.       (void) strcpy (died_from, "(alive and well)");
  1353.     }
  1354.       free_turn_flag = TRUE;
  1355.       break;
  1356.     case '=':        /* (=) set options */
  1357.       save_screen();
  1358.       set_options();
  1359.       restore_screen();
  1360.       free_turn_flag = TRUE;
  1361.       break;
  1362.     case '{':        /* ({) inscribe an object    */
  1363.       scribe_object ();
  1364.       free_turn_flag = TRUE;
  1365.       break;
  1366.     case '!':        /* (!) escape to the shell */
  1367.     case '$':
  1368. #ifdef SECURE
  1369.       msg_print("Sorry, inferior shells are not allowed from Moria.");
  1370. #else
  1371.       shell_out();
  1372. #endif
  1373.       free_turn_flag = TRUE;
  1374.       break;
  1375.     case ESCAPE:    /* (ESC)   do nothing. */
  1376.     case ' ':        /* (space) do nothing. */
  1377.       free_turn_flag = TRUE;
  1378.       break;
  1379.     case 'b':        /* (b) down, left    (1) */
  1380.       move_char(1, do_pickup);
  1381.       break;
  1382.     case 'j':        /* (j) down        (2) */
  1383.       move_char(2, do_pickup);
  1384.       break;
  1385.     case 'n':        /* (n) down, right    (3) */
  1386.       move_char(3, do_pickup);
  1387.       break;
  1388.     case 'h':        /* (h) left        (4) */
  1389.       move_char(4, do_pickup);
  1390.       break;
  1391.     case 'l':        /* (l) right        (6) */
  1392.       move_char(6, do_pickup);
  1393.       break;
  1394.     case 'y':        /* (y) up, left        (7) */
  1395.       move_char(7, do_pickup);
  1396.       break;
  1397.     case 'k':        /* (k) up        (8) */
  1398.       move_char(8, do_pickup);
  1399.       break;
  1400.     case 'u':        /* (u) up, right    (9) */
  1401.       move_char(9, do_pickup);
  1402.       break;
  1403.     case 'B':        /* (B) run down, left    (. 1) */
  1404.       find_init(1);
  1405.       break;
  1406.     case 'J':        /* (J) run down        (. 2) */
  1407.       find_init(2);
  1408.       break;
  1409.     case 'N':        /* (N) run down, right    (. 3) */
  1410.       find_init(3);
  1411.       break;
  1412.     case 'H':        /* (H) run left        (. 4) */
  1413.       find_init(4);
  1414.       break;
  1415.     case 'L':        /* (L) run right    (. 6) */
  1416.       find_init(6);
  1417.       break;
  1418.     case 'Y':        /* (Y) run up, left    (. 7) */
  1419.       find_init(7);
  1420.       break;
  1421.     case 'K':        /* (K) run up        (. 8) */
  1422.       find_init(8);
  1423.       break;
  1424.     case 'U':        /* (U) run up, right    (. 9) */
  1425.       find_init(9);
  1426.       break;
  1427.     case '/':        /* (/) identify a symbol */
  1428.       ident_char();
  1429.       free_turn_flag = TRUE;
  1430.       break;
  1431.     case '.':        /* (.) stay in one place (5) */
  1432.       move_char (5, do_pickup);
  1433.       if (command_count > 1)
  1434.     {
  1435.       command_count--;
  1436.       rest();
  1437.     }
  1438.       break;
  1439.     case '<':        /* (<) go down a staircase */
  1440.       go_up();
  1441.       break;
  1442.     case '>':        /* (>) go up a staircase */
  1443.       go_down();
  1444.       break;
  1445.     case '?':        /* (?) help with commands */
  1446.       if (rogue_like_commands)
  1447.     helpfile(MORIA_HELP);
  1448.       else
  1449.     helpfile(MORIA_ORIG_HELP);
  1450.       free_turn_flag = TRUE;
  1451.       break;
  1452.     case 'f':        /* (f)orce        (B)ash */
  1453.       bash();
  1454.       break;
  1455.     case 'C':        /* (C)haracter description */
  1456.       save_screen();
  1457.       change_name();
  1458.       restore_screen();
  1459.       free_turn_flag = TRUE;
  1460.       break;
  1461.     case 'D':        /* (D)isarm trap */
  1462.       disarm_trap();
  1463.       break;
  1464.     case 'E':        /* (E)at food */
  1465.       eat();
  1466.       break;
  1467.     case 'F':        /* (F)ill lamp */
  1468.       refill_lamp();
  1469.       break;
  1470.     case 'G':        /* (G)ain magic spells */
  1471.       gain_spells();
  1472.       break;
  1473.     case 'V':        /* (V)iew scores */
  1474.       if (last_command != 'V')
  1475.     i = TRUE;
  1476.       else
  1477.     i = FALSE;
  1478.       save_screen();
  1479.       display_scores(i);
  1480.       restore_screen();
  1481.       free_turn_flag = TRUE;
  1482.       break;
  1483.     case 'W':        /* (W)here are we on the map    (L)ocate on map */
  1484.       if ((py.flags.blind > 0) || no_light())
  1485.     msg_print("You can't see your map.");
  1486.       else
  1487.     {
  1488.       int cy, cx, p_y, p_x;
  1489.  
  1490.       y = char_row;
  1491.       x = char_col;
  1492.       if (get_panel(y, x, TRUE))
  1493.         prt_map();
  1494.       cy = panel_row;
  1495.       cx = panel_col;
  1496.       for(;;)
  1497.         {
  1498.           p_y = panel_row;
  1499.           p_x = panel_col;
  1500.           if (p_y == cy && p_x == cx)
  1501.         tmp_str[0] = '\0';
  1502.           else
  1503.         (void) sprintf(tmp_str, "%s%s of",
  1504.                    p_y < cy ? " North" : p_y > cy ? " South" : "",
  1505.                    p_x < cx ? " West" : p_x > cx ? " East" : "");
  1506.           (void) sprintf(out_val,
  1507.        "Map sector [%d,%d], which is%s your sector. Look which direction?",
  1508.                  p_y, p_x, tmp_str);
  1509.           if (!get_dir(out_val, &dir_val))
  1510.         break;
  1511. /*                                      -CJS-
  1512. // Should really use the move function, but what the hell. This
  1513. // is nicer, as it moves exactly to the same place in another
  1514. // section. The direction calculation is not intuitive. Sorry.
  1515. */
  1516.           for(;;){
  1517.         x += ((dir_val-1)%3 - 1) * SCREEN_WIDTH/2;
  1518.         y -= ((dir_val-1)/3 - 1) * SCREEN_HEIGHT/2;
  1519.         if (x < 0 || y < 0 || x >= cur_width || y >= cur_width)
  1520.           {
  1521.             msg_print("You've gone past the end of your map.");
  1522.             x -= ((dir_val-1)%3 - 1) * SCREEN_WIDTH/2;
  1523.             y += ((dir_val-1)/3 - 1) * SCREEN_HEIGHT/2;
  1524.             break;
  1525.           }
  1526.         if (get_panel(y, x, TRUE))
  1527.           {
  1528.             prt_map();
  1529.             break;
  1530.           }
  1531.           }
  1532.         }
  1533.       /* Move to a new panel - but only if really necessary. */
  1534.       if (get_panel(char_row, char_col, FALSE))
  1535.         prt_map();
  1536.     }
  1537.       free_turn_flag = TRUE;
  1538.       break;
  1539.     case 'R':        /* (R)est a while */
  1540.       rest();
  1541.       break;
  1542.     case '#':        /* (#) search toggle    (S)earch toggle */
  1543.       if (py.flags.status & PY_SEARCH)
  1544.     search_off();
  1545.       else
  1546.     search_on();
  1547.       free_turn_flag = TRUE;
  1548.       break;
  1549.     case CTRL('B'):        /* (^B) tunnel down left    (T 1) */
  1550.       tunnel(1);
  1551.       break;
  1552.     case CTRL('M'):        /* cr must be treated same as lf. */
  1553.     case CTRL('J'):        /* (^J) tunnel down        (T 2) */
  1554.       tunnel(2);
  1555.       break;
  1556.     case CTRL('N'):        /* (^N) tunnel down right    (T 3) */
  1557.       tunnel(3);
  1558.       break;
  1559.     case CTRL('H'):        /* (^H) tunnel left        (T 4) */
  1560.       tunnel(4);
  1561.       break;
  1562.     case CTRL('L'):        /* (^L) tunnel right        (T 6) */
  1563.       tunnel(6);
  1564.       break;
  1565.     case CTRL('Y'):        /* (^Y) tunnel up left        (T 7) */
  1566.       tunnel(7);
  1567.       break;
  1568.     case CTRL('K'):        /* (^K) tunnel up        (T 8) */
  1569.       tunnel(8);
  1570.       break;
  1571.     case CTRL('U'):        /* (^U) tunnel up right        (T 9) */
  1572.       tunnel(9);
  1573.       break;
  1574.     case 'z':        /* (z)ap a wand        (a)im a wand */
  1575.       aim();
  1576.       break;
  1577.     case 'M':
  1578.       screen_map();
  1579.       free_turn_flag = TRUE;
  1580.       break;
  1581.     case 'P':        /* (P)eruse a book    (B)rowse in a book */
  1582.       examine_book();
  1583.       free_turn_flag = TRUE;
  1584.       break;
  1585.     case 'c':        /* (c)lose an object */
  1586.       closeobject();
  1587.       break;
  1588.     case 'd':        /* (d)rop something */
  1589.       inven_command('d');
  1590.       break;
  1591.     case 'e':        /* (e)quipment list */
  1592.       inven_command('e');
  1593.       break;
  1594.     case 't':        /* (t)hrow something    (f)ire something */
  1595.       throw_object();
  1596.       break;
  1597.     case 'i':        /* (i)nventory list */
  1598.       inven_command('i');
  1599.       break;
  1600.     case 'S':        /* (S)pike a door    (j)am a door */
  1601.       jamdoor();
  1602.       break;
  1603.     case 'x':        /* e(x)amine surrounds    (l)ook about */
  1604.       look();
  1605.       free_turn_flag = TRUE;
  1606.       break;
  1607.     case 'm':        /* (m)agic spells */
  1608.       cast();
  1609.       break;
  1610.     case 'o':        /* (o)pen something */
  1611.       openobject();
  1612.       break;
  1613.     case 'p':        /* (p)ray */
  1614.       pray();
  1615.       break;
  1616.     case 'q':        /* (q)uaff */
  1617.       quaff();
  1618.       break;
  1619.     case 'r':        /* (r)ead */
  1620.       read_scroll();
  1621.       break;
  1622.     case 's':        /* (s)earch for a turn */
  1623.       search(char_row, char_col, py.misc.srh);
  1624.       break;
  1625.     case 'T':        /* (T)ake off something    (t)ake off */
  1626.       inven_command('t');
  1627.       break;
  1628.     case 'Z':        /* (Z)ap a staff    (u)se a staff */
  1629.       use();
  1630.       break;
  1631.     case 'v':        /* (v)ersion of game */
  1632.       helpfile(MORIA_VER);
  1633.       free_turn_flag = TRUE;
  1634.       break;
  1635.     case 'w':        /* (w)ear or wield */
  1636.       inven_command('w');
  1637.       break;
  1638.     case 'X':        /* e(X)change weapons    e(x)change */
  1639.       inven_command('x');
  1640.       break;
  1641.     default:
  1642.       if (wizard)
  1643.     {
  1644.       free_turn_flag = TRUE; /* Wizard commands are free moves*/
  1645.       switch(com_val)
  1646.         {
  1647.         case CTRL('A'):    /*^A = Cure all*/
  1648.           (void) remove_curse();
  1649.           (void) cure_blindness();
  1650.           (void) cure_confusion();
  1651.           (void) cure_poison();
  1652.           (void) remove_fear();
  1653.           (void) res_stat(A_STR);
  1654.           (void) res_stat(A_INT);
  1655.           (void) res_stat(A_WIS);
  1656.           (void) res_stat(A_CON);
  1657.           (void) res_stat(A_DEX);
  1658.           (void) res_stat(A_CHR);
  1659.           f_ptr = &py.flags;
  1660.           if (f_ptr->slow > 1)
  1661.         f_ptr->slow = 1;
  1662.           if (f_ptr->image > 1)
  1663.         f_ptr->image = 1;
  1664.           break;
  1665.         case CTRL('E'):    /*^E = wizchar */
  1666.           change_character();
  1667.           erase_line(MSG_LINE, 0);
  1668.           break;
  1669.         case CTRL('F'):    /*^F = genocide*/
  1670.           (void) mass_genocide();
  1671.           break;
  1672.         case CTRL('G'):    /*^G = treasure*/
  1673.           if (command_count > 0)
  1674.         {
  1675.           i = command_count;
  1676.           command_count = 0;
  1677.         }
  1678.           else
  1679.         i = 1;
  1680.           random_object(char_row, char_col, i);
  1681.           prt_map();
  1682.           break;
  1683.         case CTRL('D'):    /*^D = up/down */
  1684.           if (command_count > 0)
  1685.         {
  1686.           if (command_count > 99)
  1687.             i = 0;
  1688.           else
  1689.             i = command_count;
  1690.           command_count = 0;
  1691.         }
  1692.           else
  1693.         {
  1694.           prt("Go to which level (0-99) ? ", 0, 0);
  1695.           i = -1;
  1696.           if (get_string(tmp_str, 0, 27, 10))
  1697.             i = atoi(tmp_str);
  1698.         }
  1699.           if (i > -1)
  1700.         {
  1701.           dun_level = i;
  1702.           if (dun_level > 99)
  1703.             dun_level = 99;
  1704.           new_level_flag = TRUE;
  1705.         }
  1706.           else
  1707.         erase_line(MSG_LINE, 0);
  1708.           break;
  1709.         case CTRL('O'):    /*^O = objects */
  1710.           print_objects();
  1711.           break;
  1712.         case '\\': /* \ wizard help */
  1713.           if (rogue_like_commands)
  1714.         helpfile(MORIA_WIZ_HELP);
  1715.           else
  1716.         helpfile(MORIA_OWIZ_HELP);
  1717.           break;
  1718.         case CTRL('I'):    /*^I = identify*/
  1719.           (void) ident_spell();
  1720.           break;
  1721.         case '*':
  1722.           wizard_light();
  1723.           break;
  1724.         case ':':
  1725.           map_area();
  1726.           break;
  1727.         case CTRL('T'):    /*^T = teleport*/
  1728.           teleport(100);
  1729.           break;
  1730.         case '+':
  1731.           if (command_count > 0)
  1732.         {
  1733.           py.misc.exp = command_count;
  1734.           command_count = 0;
  1735.         }
  1736.           else if (py.misc.exp == 0)
  1737.         py.misc.exp = 1;
  1738.           else
  1739.         py.misc.exp = py.misc.exp * 2;
  1740.           prt_experience();
  1741.           break;
  1742.         case '&':    /*& = summon  */
  1743.           y = char_row;
  1744.           x = char_col;
  1745.           (void) summon_monster(&y, &x, TRUE);
  1746.           creatures(FALSE);
  1747.           break;
  1748.         case '@':
  1749.           wizard_create();
  1750.           break;
  1751.         default:
  1752.           if (rogue_like_commands)
  1753.         prt("Type '?' or '\\' for help.", 0, 0);
  1754.           else
  1755.         prt("Type '?' or ^H for help.", 0, 0);
  1756.         }
  1757.     }
  1758.       else
  1759.     {
  1760.       prt("Type '?' for help.", 0, 0);
  1761.       free_turn_flag = TRUE;
  1762.     }
  1763.     }
  1764.   last_command = com_val;
  1765. }
  1766.  
  1767. /* Check whether this command will accept a count.     -CJS-  */
  1768. static int valid_countcommand(c)
  1769. char c;
  1770. {
  1771.   switch(c)
  1772.     {
  1773.     case 'Q':
  1774.     case CTRL('W'):
  1775.     case CTRL('X'):
  1776.     case '=':
  1777.     case '{':
  1778.     case '/':
  1779.     case '<':
  1780.     case '>':
  1781.     case '?':
  1782.     case 'C':
  1783.     case 'E':
  1784.     case 'F':
  1785.     case 'G':
  1786.     case 'V':
  1787.     case '#':
  1788.     case 'z':
  1789.     case 'P':
  1790.     case 'c':
  1791.     case 'd':
  1792.     case 'e':
  1793.     case 't':
  1794.     case 'i':
  1795.     case 'x':
  1796.     case 'm':
  1797.     case 'p':
  1798.     case 'q':
  1799.     case 'r':
  1800.     case 'T':
  1801.     case 'Z':
  1802.     case 'v':
  1803.     case 'w':
  1804.     case 'W':
  1805.     case 'X':
  1806.     case CTRL('A'):
  1807.     case '\\':
  1808.     case CTRL('I'):
  1809.     case '*':
  1810.     case ':':
  1811.     case CTRL('T'):
  1812.     case CTRL('E'):
  1813.     case CTRL('F'):
  1814.     case CTRL('S'):
  1815.     case CTRL('Q'):
  1816.       return FALSE;
  1817.     case CTRL('P'):
  1818.     case ESCAPE:
  1819.     case ' ':
  1820.     case '-':
  1821.     case 'b':
  1822.     case 'f':
  1823.     case 'j':
  1824.     case 'n':
  1825.     case 'h':
  1826.     case 'l':
  1827.     case 'y':
  1828.     case 'k':
  1829.     case 'u':
  1830.     case '.':
  1831.     case 'B':
  1832.     case 'J':
  1833.     case 'N':
  1834.     case 'H':
  1835.     case 'L':
  1836.     case 'Y':
  1837.     case 'K':
  1838.     case 'U':
  1839.     case 'D':
  1840.     case 'R':
  1841.     case CTRL('Y'):
  1842.     case CTRL('K'):
  1843.     case CTRL('U'):
  1844.     case CTRL('L'):
  1845.     case CTRL('N'):
  1846.     case CTRL('J'):
  1847.     case CTRL('B'):
  1848.     case CTRL('H'):
  1849.     case 'S':
  1850.     case 'o':
  1851.     case 's':
  1852.     case CTRL('D'):
  1853.     case CTRL('G'):
  1854.     case '+':
  1855.       return TRUE;
  1856.     default:
  1857.       return FALSE;
  1858.     }
  1859. }
  1860.  
  1861.  
  1862. /* Regenerate hit points                -RAK-    */
  1863. static void regenhp(percent)
  1864. int percent;
  1865. {
  1866.   register struct misc *p_ptr;
  1867.   register int32 new_chp, new_chp_frac;
  1868.   int old_chp;
  1869.  
  1870.   p_ptr = &py.misc;
  1871.   old_chp = p_ptr->chp;
  1872.   new_chp = ((long)p_ptr->mhp) * percent + PLAYER_REGEN_HPBASE;
  1873.   p_ptr->chp += new_chp >> 16;    /* div 65536 */
  1874.   /* check for overflow */
  1875.   if (p_ptr->chp < 0 && old_chp > 0)
  1876.     p_ptr->chp = MAX_SHORT;
  1877.   new_chp_frac = (new_chp & 0xFFFF) + p_ptr->chp_frac; /* mod 65536 */
  1878.   if (new_chp_frac >= 0x10000L)
  1879.     {
  1880.       p_ptr->chp_frac = new_chp_frac - 0x10000L;
  1881.       p_ptr->chp++;
  1882.     }
  1883.   else
  1884.     p_ptr->chp_frac = new_chp_frac;
  1885.  
  1886.   /* must set frac to zero even if equal */
  1887.   if (p_ptr->chp >= p_ptr->mhp)
  1888.     {
  1889.       p_ptr->chp = p_ptr->mhp;
  1890.       p_ptr->chp_frac = 0;
  1891.     }
  1892.   if (old_chp != p_ptr->chp)
  1893.     prt_chp();
  1894. }
  1895.  
  1896.  
  1897. /* Regenerate mana points                -RAK-    */
  1898. static void regenmana(percent)
  1899. int percent;
  1900. {
  1901.   register struct misc *p_ptr;
  1902.   register int32 new_mana, new_mana_frac;
  1903.   int old_cmana;
  1904.  
  1905.   p_ptr = &py.misc;
  1906.   old_cmana = p_ptr->cmana;
  1907.   new_mana = ((long)p_ptr->mana) * percent + PLAYER_REGEN_MNBASE;
  1908.   p_ptr->cmana += new_mana >> 16;  /* div 65536 */
  1909.   /* check for overflow */
  1910.   if (p_ptr->cmana < 0 && old_cmana > 0)
  1911.     p_ptr->cmana = MAX_SHORT;
  1912.   new_mana_frac = (new_mana & 0xFFFF) + p_ptr->cmana_frac; /* mod 65536 */
  1913.   if (new_mana_frac >= 0x10000L)
  1914.     {
  1915.       p_ptr->cmana_frac = new_mana_frac - 0x10000L;
  1916.       p_ptr->cmana++;
  1917.     }
  1918.   else
  1919.     p_ptr->cmana_frac = new_mana_frac;
  1920.  
  1921.   /* must set frac to zero even if equal */
  1922.   if (p_ptr->cmana >= p_ptr->mana)
  1923.     {
  1924.       p_ptr->cmana = p_ptr->mana;
  1925.       p_ptr->cmana_frac = 0;
  1926.     }
  1927.   if (old_cmana != p_ptr->cmana)
  1928.     prt_cmana();
  1929. }
  1930.  
  1931.  
  1932. /* Is an item an enchanted weapon or armor and we don't know?  -CJS- */
  1933. /* only returns true if it is a good enchantment */
  1934. static int enchanted (t_ptr)
  1935. register inven_type *t_ptr;
  1936. {
  1937. #ifdef ATARIST_MWC
  1938.   int32u holder;
  1939. #endif
  1940.  
  1941.   if (t_ptr->tval < TV_MIN_ENCHANT || t_ptr->tval > TV_MAX_ENCHANT
  1942. #ifdef ATARIST_MWC
  1943.       || t_ptr->flags & (holder = TR_CURSED))
  1944. #else
  1945.       || t_ptr->flags & TR_CURSED)
  1946. #endif
  1947.     return FALSE;
  1948.   if (known2_p(t_ptr))
  1949.     return FALSE;
  1950.   if (t_ptr->ident & ID_MAGIK)
  1951.     return FALSE;
  1952.   if (t_ptr->tohit > 0 || t_ptr->todam > 0 || t_ptr->toac > 0)
  1953.     return TRUE;
  1954.   if ((0x4000107fL & t_ptr->flags) && t_ptr->p1 > 0)
  1955.     return TRUE;
  1956.   if (0x07ffe980L & t_ptr->flags)
  1957.     return TRUE;
  1958.  
  1959.   return FALSE;
  1960. }
  1961.  
  1962.  
  1963. /* Examine a Book                    -RAK-    */
  1964. static void examine_book()
  1965. {
  1966.   int32u j;
  1967.   int i, k, item_val, flag;
  1968.   int spell_index[31];
  1969.   register inven_type *i_ptr;
  1970.   register spell_type *s_ptr;
  1971.  
  1972.   if (!find_range(TV_MAGIC_BOOK, TV_PRAYER_BOOK, &i, &k))
  1973.     msg_print("You are not carrying any books.");
  1974.   else if (py.flags.blind > 0)
  1975.     msg_print("You can't see to read your spell book!");
  1976.   else if (no_light())
  1977.     msg_print("You have no light to read by.");
  1978.   else if (py.flags.confused > 0)
  1979.     msg_print("You are too confused.");
  1980.   else if (get_item(&item_val, "Which Book?", i, k, CNIL, CNIL))
  1981.     {
  1982.       flag = TRUE;
  1983.       i_ptr = &inventory[item_val];
  1984.       if (class[py.misc.pclass].spell == MAGE)
  1985.     {
  1986.       if (i_ptr->tval != TV_MAGIC_BOOK)
  1987.         flag = FALSE;
  1988.     }
  1989.       else if (class[py.misc.pclass].spell == PRIEST)
  1990.     {
  1991.       if (i_ptr->tval != TV_PRAYER_BOOK)
  1992.         flag = FALSE;
  1993.     }
  1994.       else
  1995.     flag = FALSE;
  1996.  
  1997.       if (!flag)
  1998.     msg_print("You do not understand the language.");
  1999.       else
  2000.     {
  2001.       i = 0;
  2002.       j = inventory[item_val].flags;
  2003.       while (j)
  2004.         {
  2005.           k = bit_pos(&j);
  2006.           s_ptr = &magic_spell[py.misc.pclass-1][k];
  2007.           if (s_ptr->slevel < 99)
  2008.         {
  2009.           spell_index[i] = k;
  2010.           i++;
  2011.         }
  2012.         }
  2013.       save_screen();
  2014.       print_spells(spell_index, i, TRUE, -1);
  2015.       pause_line(0);
  2016.       restore_screen();
  2017.     }
  2018.     }
  2019. }
  2020.  
  2021.  
  2022. /* Go up one level                    -RAK-    */
  2023. static void go_up()
  2024. {
  2025.   register cave_type *c_ptr;
  2026.   register int no_stairs = FALSE;
  2027.  
  2028.   c_ptr = &cave[char_row][char_col];
  2029.   if (c_ptr->tptr != 0)
  2030.     if (t_list[c_ptr->tptr].tval == TV_UP_STAIR)
  2031.       {
  2032.     dun_level--;
  2033.     new_level_flag = TRUE;
  2034.     msg_print("You enter a maze of up staircases.");
  2035.     msg_print("You pass through a one-way door.");
  2036.       }
  2037.     else
  2038.       no_stairs = TRUE;
  2039.   else
  2040.     no_stairs = TRUE;
  2041.  
  2042.   if (no_stairs)
  2043.     {
  2044.       msg_print("I see no up staircase here.");
  2045.       free_turn_flag = TRUE;
  2046.     }
  2047. }
  2048.  
  2049.  
  2050. /* Go down one level                    -RAK-    */
  2051. static void go_down()
  2052. {
  2053.   register cave_type *c_ptr;
  2054.   register int no_stairs = FALSE;
  2055.  
  2056.   c_ptr = &cave[char_row][char_col];
  2057.   if (c_ptr->tptr != 0)
  2058.     if (t_list[c_ptr->tptr].tval == TV_DOWN_STAIR)
  2059.       {
  2060.     dun_level++;
  2061.     new_level_flag = TRUE;
  2062.     msg_print("You enter a maze of down staircases.");
  2063.     msg_print("You pass through a one-way door.");
  2064.       }
  2065.     else
  2066.       no_stairs = TRUE;
  2067.   else
  2068.     no_stairs = TRUE;
  2069.  
  2070.   if (no_stairs)
  2071.     {
  2072.       msg_print("I see no down staircase here.");
  2073.       free_turn_flag = TRUE;
  2074.     }
  2075. }
  2076.  
  2077.  
  2078. /* Jam a closed door                    -RAK-    */
  2079. static void jamdoor()
  2080. {
  2081.   int y, x, dir, i, j;
  2082.   register cave_type *c_ptr;
  2083.   register inven_type *t_ptr, *i_ptr;
  2084.   char tmp_str[80];
  2085.  
  2086.   free_turn_flag = TRUE;
  2087.   y = char_row;
  2088.   x = char_col;
  2089.   if (get_dir(CNIL, &dir))
  2090.     {
  2091.       (void) mmove(dir, &y, &x);
  2092.       c_ptr = &cave[y][x];
  2093.       if (c_ptr->tptr != 0)
  2094.     {
  2095.       t_ptr = &t_list[c_ptr->tptr];
  2096.       if (t_ptr->tval == TV_CLOSED_DOOR)
  2097.         if (c_ptr->cptr == 0)
  2098.           {
  2099.         if (find_range(TV_SPIKE, TV_NEVER, &i, &j))
  2100.           {
  2101.             free_turn_flag = FALSE;
  2102.             count_msg_print("You jam the door with a spike.");
  2103.             if (t_ptr->p1 > 0)
  2104.               t_ptr->p1 = -t_ptr->p1;    /* Make locked to stuck. */
  2105.             /* Successive spikes have a progressively smaller effect.
  2106.                Series is: 0 20 30 37 43 48 52 56 60 64 67 70 ... */
  2107.             t_ptr->p1 -= 1 + 190 / (10 - t_ptr->p1);
  2108.             i_ptr = &inventory[i];
  2109.             if (i_ptr->number > 1)
  2110.               {
  2111.             i_ptr->number--;
  2112.             inven_weight -= i_ptr->weight;
  2113.               }
  2114.             else
  2115.               inven_destroy(i);
  2116.           }
  2117.         else
  2118.           msg_print("But you have no spikes.");
  2119.           }
  2120.         else
  2121.           {
  2122.         free_turn_flag = FALSE;
  2123.         (void) sprintf(tmp_str, "The %s is in your way!",
  2124.                    c_list[m_list[c_ptr->cptr].mptr].name);
  2125.         msg_print(tmp_str);
  2126.           }
  2127.       else if (t_ptr->tval == TV_OPEN_DOOR)
  2128.         msg_print("The door must be closed first.");
  2129.       else
  2130.         msg_print("That isn't a door!");
  2131.     }
  2132.       else
  2133.     msg_print("That isn't a door!");
  2134.     }
  2135. }
  2136.  
  2137.  
  2138. /* Refill the players lamp                -RAK-    */
  2139. static void refill_lamp()
  2140. {
  2141.   int i, j;
  2142.   register int k;
  2143.   register inven_type *i_ptr;
  2144.  
  2145.   free_turn_flag = TRUE;
  2146.   k = inventory[INVEN_LIGHT].subval;
  2147.   if (k != 0)
  2148.     msg_print("But you are not using a lamp.");
  2149.   else if (!find_range(TV_FLASK, TV_NEVER, &i, &j))
  2150.     msg_print("You have no oil.");
  2151.   else
  2152.     {
  2153.       free_turn_flag = FALSE;
  2154.       i_ptr = &inventory[INVEN_LIGHT];
  2155.       i_ptr->p1 += inventory[i].p1;
  2156.       if (i_ptr->p1 > OBJ_LAMP_MAX)
  2157.     {
  2158.       i_ptr->p1 = OBJ_LAMP_MAX;
  2159.       msg_print ("Your lamp overflows, spilling oil on the ground.");
  2160.       msg_print("Your lamp is full.");
  2161.     }
  2162.       else if (i_ptr->p1 > OBJ_LAMP_MAX/2)
  2163.     msg_print ("Your lamp is more than half full.");
  2164.       else if (i_ptr->p1 == OBJ_LAMP_MAX/2)
  2165.     msg_print ("Your lamp is half full.");
  2166.       else
  2167.     msg_print ("Your lamp is less than half full.");
  2168.       desc_remain(i);
  2169.       inven_destroy(i);
  2170.     }
  2171. }
  2172.